<template>
  <a-modal v-model:visible="visible" :title="modalTitle" width="35%" @ok="handleOk" @cancel="handleCancel">
    <a-form :model="formState" ref="formRef" :label-col="{ span: 5 }">
      <a-form-item label="类型" name="type" :rules="[{ required: true, message: '请选择类型' }]">
        <a-radio-group v-model:value="formState.type">
          <a-radio :value="1">同意</a-radio>
          <a-radio :value="2">拒绝</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="理由" name="remark" v-if="formState.type == 2" :rules="[{ required: true, message: '请输入理由' }]">
        <a-textarea v-model:value="formState.remark" placeholder="请输入理由" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import useModal from "@/utils/useModal";
import { reactive, ref } from "vue";
import { cashAudit } from "@/api/user";

import { message } from "ant-design-vue";
const emits = defineEmits(["modal-success"]);

const formRef = ref();
const { visible, modalTitle } = useModal();
const formState = reactive({
  id: null,
  type: null,
  remark: "",
});
const show = (model) => {
  visible.value = true;
  modalTitle.value = "审核";
  formState.id = model.cash_id
};
const handleOk = async () => {
  await formRef.value.validate().then(() => {
    cashAudit({
      id: formState.id,
      ...formState,
    }).then((res) => {
      if (res.code == 0) {
        visible.value = false;
        message.success(res.msg);
        formRef.value.resetFields();
        emits("modal-success");
      }
    });
  })

};
const handleCancel = function () {
  modalRef.value.resetFields();
};
// 暴露方法
defineExpose({ show });
</script>
